//
//  ViewController.m
//  ImageProcesssing
//
//  Created by enrique leo on 6/1/21.
//

#import "ViewController.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import "ImageProcessing.h"
#import "AFNetworking.h"
#import "Masonry.h"
#import "JXButton.h"


@interface ViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _write = [UIButton buttonWithType: UIButtonTypeContactAdd];
    //[_write setTitle:@"发布" forState:UIControlStateNormal];
    [_write addTarget:self action:@selector(openAlbum) forControlEvents:UIControlEventTouchUpInside];

    //[self.view addSubview:_write];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:_write];
    rightItem.imageInsets = UIEdgeInsetsMake(0, -15,0, 0);//设置向左偏移
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
//    JXButton *dogButton = [[JXButton alloc] initWithFrame:CGRectMake(20, 100, 100, 100)];
//    [dogButton setTitle:@"Oh,Dog!" forState:0];
//    [dogButton setTitleColor:[UIColor blackColor] forState:0];
//    [dogButton setImage:[UIImage imageNamed:@"3.jpg"] forState:0];
//    [self.view addSubview:dogButton];
}

- (void)openAlbum{
    UIImagePickerController *imagePicker= [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//    imagePicker.mediaTypes = @[(NSString *)kUTTypeImage];
    imagePicker.mediaTypes = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeMovie];
    imagePicker.allowsEditing = NO;
    imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
//
//    // dismiss UIImagePickerController
//    [self dismissViewControllerAnimated:YES completion:nil];
//    // 选择的图片信息存储于info字典中
//    NSLog(@"%@", info);
//}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *img = info[@"UIImagePickerControllerOriginalImage"];
    ImageProcessing *imgProc = [[ImageProcessing alloc]init:img];
    imgProc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imgProc animated:YES completion:nil];
}

//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}


@end
